<#include "/common/taglibs.ftl" />
<@menu code='${entityName!}'/>
<title><@spring.message code="${entityName!}" /> - <@spring.message code="${op}" /></title>
<div class="m-portlet">
    <div class="m-portlet__head">
        <div class="m-portlet__head-caption">
            <div class="m-portlet__head-title">
                <span class="m-portlet__head-icon">
                    <i class="flaticon-calendar"></i>
                </span>
                <h3 class="m-portlet__head-text m--font-primary">
                    <@spring.message code="${entityName!}" /> / <@spring.message code="${op}" />
                    <#if op != 'op.view'>
                    （<@spring.message code="reuqired.tips"/>）
                    </#if>
                </h3>
            </div>
        </div>
        <@formHeaderButtons resourceIdentity='${resourceIdentity!}' baseUrl='${baseUrl!}'/>
    </div>
    <!--begin::Form-->
    <form class="m-form m-form--fit m-form--label-align-right" method="post" id="mainForm">
        <div class="m-portlet__body">
            <div class="m-form__content">
                <@showFieldErrors commandName="m" />
                <#include "/common/taglibs/validationMessage.ftl">
            </div>
            <input type="hidden" class="form-control" id="id" name="id" value="${(m.id)!}"/>
            <div class="form-group m-form__group row">
                <label class="col-form-label col-lg-3 col-sm-12"><@spring.message code="role.name"/><span class="required"> * </span></label>
                <div class="col-lg-4 col-md-9 col-sm-12">
                    <input type="text" placeholder="" class="form-control" name="name" value="${(m.name)!}" required/>
                </div>
            </div>
            <div class="form-group m-form__group row">
                <label class="col-form-label col-lg-3 col-sm-12"><@spring.message code="role.code"/></label>
                <div class="col-lg-4 col-md-9 col-sm-12">
                    <input type="text" placeholder="" class="form-control" name="code" value="${(m.code)!}"/>
                </div>
            </div>
            <div class="form-group m-form__group row">
                <label class="col-form-label col-lg-3 col-sm-12"><@spring.message code="role.description"/></label>
                <div class="col-lg-4 col-md-9 col-sm-12">
                    <textarea class="form-control" rows="3" name="description" >${(m.description)!}</textarea>
                </div>
            </div>
            <div class="form-group m-form__group row">
                <label class="col-form-label col-lg-3 col-sm-12"><@spring.message code="role.default"/></label></label>
                <div class="col-lg-4 col-md-9 col-sm-12">
                <@switchButton inputName="defaultRole" on=m.defaultRole />
                </div>
            </div>
            <div class="form-group m-form__group row">
                <label class="col-form-label col-lg-3 col-sm-12"><@spring.message code="activated"/></label>
                <div class="col-lg-4 col-md-9 col-sm-12">
                    <@switchButton inputName="activated" on=m.activated />
                </div>
            </div>
            <div class="form-group m-form__group row">
                <label class="col-form-label col-lg-3 col-sm-12"><@spring.message code="assign.permission"/></label>
                <div class="col-lg-4 col-md-9 col-sm-12">
                    <input type="hidden" id="permissionId" name="permissionIds" value="${(m.permissionIds)!?join(',','')}">
                    <div class="input-group">
                        <input type="text" id="permissionName" class="form-control m-input" placeholder='- - - - -   <@spring.message code="please.choose"/>   - - - - -' readonly >
                        <div class="input-group-append">
							<span class="input-group-text">
								<i class="la la-angle-down"></i>
							</span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="form-group m-form__group row">
                <label class="col-form-label col-lg-3 col-sm-12"><@spring.message code="assigned.permission"/></label>
                <div class="col-lg-4 col-md-9 col-sm-12">
                    <textarea class="form-control" id="selectedPermissionName" rows="3" readonly></textarea>
                </div>
            </div>
        </div>
        <@formFooterButtons resourceIdentity='${resourceIdentity!}' baseUrl='${baseUrl!}'/>
    </form>
    <!--end::Form-->
</div>
<page-plugin-style>
<#include "/common/plugins/jquery.ztree.style.ftl" />
</page-plugin-style>
<page-plugin-script>
<#include "/common/plugins/jquery.ztree.script.ftl" />
</page-plugin-script>
<page-style>
</page-style>
<page-script>
	<script>
        jQuery(document).ready(function() {
            var $form = $("#mainForm")
            <#if op == 'op.view'>
                $.m.form.readonly($form, false);
            </#if>
            $.m.form.initValue("activated", "${(m.activated)!?string('true','false')}");
            $.m.form.initValue("defaultRole", "${(m.defaultRole)!?string('true','false')}");
            $.m.form.validate($form, {
                rules: {
                    name: {
                        minlength: 2,
                        required: true
                    }
                }
            });

            $.m.system.auth.initSelectPermission();
        });
	</script>
</page-script>